// 题意：求树上距离小于等于k的点对数
//
// 题解：点分治，找到重心分而治之，每次找同一个子树的点对，
//       经过根节点的点对和以根为一个端点的点对，每次求完之后，
//       找到所有点到重心的距离，排序然后O(n)统计对数，注意经过根节点
//       的点对会算重复要减去。复杂度是O(n*log(n)*log(n))，
//       如果用基数排序可以到复杂度O(n*l*log(n)), 这里的l是k的位数，
//       这里l=10。
//
// run: time $exec < input
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>

int const inf = 1 << 28;
int const maxn = 10007;
bool centroid[maxn];
int subtree_size[maxn];

// [from] first: to, second: cost
typedef std::pair<int, int> node_type;
typedef std::vector<node_type> adj_edge;
typedef adj_edge::iterator edge_iter;
//typedef std::vector<adj_edge> graph_type;
//graph_type graph;
adj_edge graph[maxn];

int n, k, ans;

int calc_subtree_size(int u, int p)
{
	int c = 1;
	for (edge_iter it = graph[u].begin(); it != graph[u].end(); ++it) {
		int v = it->first;
		if (centroid[v] || p == v) continue;
		c += calc_subtree_size(v, u);
	}
	return subtree_size[u] = c;
}

std::pair<int, int> get_center(int u, int p, int all)
{
	std::pair<int, int> res = std::make_pair(inf, -1);
	int sum = 1, max_sub = 0;
	for (edge_iter it = graph[u].begin(); it != graph[u].end(); ++it) {
		int v = it->first;
		if (centroid[v] || v == p) continue;
		max_sub = std::max(max_sub, subtree_size[v]);
		sum += subtree_size[v];
		res = std::min(res, get_center(v, u, all));
	}
	max_sub = std::max(max_sub, all - sum);
	return std::min(res, std::make_pair(max_sub, u));
}

void calc_dis_to_center(int u, int p, int dis, std::vector<int> & count)
{
	count.push_back(dis);
	for (edge_iter it = graph[u].begin(); it != graph[u].end(); ++it) {
		int v = it->first, c = it->second;
		if (centroid[v] || v == p) continue;
		calc_dis_to_center(v, u, c + dis, count);
	}
}

int calc_pair(std::vector<int> & count)
{
	std::sort(count.begin(), count.end());
	int len = count.size(), tot = 0;
	for (int l = 0, r = len - 1; l < r; l++) {
		for (; l < r && count[l] + count[r] > k; r--);
		tot += r - l;
	}
	return tot;
}

void divide_and_conquer_for_tree(int u)
{
	calc_subtree_size(u, -1);
	int center = get_center(u, -1, subtree_size[u]).second;
	centroid[center] = true;

	for (edge_iter it = graph[center].begin(); it != graph[center].end(); ++it) {
		int v = it->first;
		if (centroid[v]) continue;
		divide_and_conquer_for_tree(v);
	}

	std::vector<int> count(1);
	for (edge_iter it = graph[center].begin(); it != graph[center].end(); ++it) {
		int v = it->first, c = it->second;
		if (centroid[v]) continue;
		std::vector<int> tmp_count;
		calc_dis_to_center(v, center, c, tmp_count);
		ans -= calc_pair(tmp_count);
		count.insert(count.end(), tmp_count.begin(), tmp_count.end());
	}
	ans += calc_pair(count);
	centroid[center] = false;
}

int main()
{
	while (std::scanf("%d%d", &n, &k) && (n || k)) {
		for (int i = 0; i < n; i++) graph[i].clear();
		for (int i = 1, x, y; i < n; i++) {
			node_type tmp;
			std::scanf("%d%d%d", &x, &y, &tmp.second);
			x--; y--;
			tmp.first = y; graph[x].push_back(tmp);
			tmp.first = x; graph[y].push_back(tmp);
		}

		ans = 0;
		divide_and_conquer_for_tree(0);
		std::printf("%d\n", ans);
	}
}

